# -*- shell-script -*-

# Demonstration of the init-platform functionality

# This script fragment is sourced by /etc/init.d/init-arch.sh, which
# in turn executes the init_platform_pre_arch() and
# init_platform_post_arch() functions.

# A machine can use this feature to run any early boot scripts needed
# by the machine.  A typical usage would be to initialize specific
# hardware devices.

init_usb_hub() {
    i2cset -y 1 0x70 0 1 b

    i2cset -y 1 0x2c 0x00 0x01 0x24 i
    i2cset -y 1 0x2c 0x01 0x01 0x04 i
    i2cset -y 1 0x2c 0x02 0x01 0x14 i
    i2cset -y 1 0x2c 0x03 0x01 0x25 i
    i2cset -y 1 0x2c 0x04 0x01 0xb3 i
    i2cset -y 1 0x2c 0x05 0x01 0x0b i
    i2cset -y 1 0x2c 0x06 0x01 0x9b i
    i2cset -y 1 0x2c 0x07 0x01 0x20 i
    i2cset -y 1 0x2c 0x08 0x01 0x02 i
    i2cset -y 1 0x2c 0x09 0x01 0x00 i
    i2cset -y 1 0x2c 0x0a 0x01 0x00 i
    i2cset -y 1 0x2c 0x0b 0x01 0x00 i
    i2cset -y 1 0x2c 0x0c 0x01 0x01 i
    i2cset -y 1 0x2c 0x0d 0x01 0x32 i
    i2cset -y 1 0x2c 0x0e 0x01 0x01 i
    i2cset -y 1 0x2c 0x0f 0x01 0x32 i
    i2cset -y 1 0x2c 0x10 0x01 0x32 i
    i2cset -y 1 0x2c 0x11 0x01 0x00 i
    i2cset -y 1 0x2c 0x12 0x01 0x00 i
    i2cset -y 1 0x2c 0x13 0x01 0x00 i
    i2cset -y 1 0x2c 0x14 0x01 0x00 i
    i2cset -y 1 0x2c 0x15 0x01 0x00 i

    for i in $(seq $(printf "%d %d" 0x16 0xcf) ); do
        i2cset -y 1 0x2c 0x$(printf "%x" $i) 0x01 0x00 i
    done

    i2cset -y 1 0x2c 0xd0 0x01 0x00 i

    i2cset -y 1 0x2c 0xe0 0x01 0x00 i

    for i in $(seq $(printf "%d %d" 0xf5 0xfc) ); do
        i2cset -y 1 0x2c 0x$(printf "%x" $i) 0x01 0x00 i
    done

    i2cset -y 1 0x2c 0xff 0x01 0x01 i
}

# Use this function to perform any initializations required by the
# architecture specific initialization.  This function executes before
# the architecture initializations.
init_platform_pre_arch() {
    init_usb_hub 2>/dev/null
}
